Ext.namespace("Ext.milan.pagejs.page_modulepermissions");

Ext.milan.pagejs.page_modulepermissions.setPer = function(ele)
{
	var formEle = ele.form;
	
	new Milan.widget.ComfirmDialog("确认信息","您确定要设置受控权限吗？",
	{
		confirmCallback : function(){
			formEle.actionType.value=5;
			Milan.ajaxutility.formSubmit(
		    {
		        form: formEle.id,
		        success: function(){
					Milan.ajaxutility.formSubmit(
				    {
				        url: "checkpermissionAction.do?actionType=2&selectmenu=3",
				        success : function(response,option)
						{
							Milan.pagejs.page_index.updateCurrentTab(response.responseText);
						}
				    });
				}
		    });
		},
		cancelCallback : function(){}
	});
}

Ext.milan.pagejs.page_modulepermissions.chkClick = function(chkObj)
{
	var formEle = chkObj.form;
	var tmpObj;
	var selects = formEle.CompChk;
	for (var i=0;i<selects.length;i++)
	{
		if (selects[i].CompID==chkObj.CompID) 
		{
			tmpObj=selects[i];
			break;
		}
	}
	
	selects = formEle.chkper;
	var trueI =0;
	var falseI=0;
	for (var i=0;i<selects.length;i++)
	{
		if (selects[i].CompID==chkObj.CompID)
		{
			if (selects[i].checked)
				trueI++;
			else
				falseI++;
		}
	}

	if (falseI==0)
		tmpObj.checked=true;
	else
		tmpObj.checked=false;
		
}

Ext.milan.pagejs.page_modulepermissions.chkComp = function(chkObj)		//选中模块
{
	var formEle = chkObj.form;
	var ch=false;
	var i=0;
	
	if (chkObj.checked) ch=true;
	
	var selects = formEle.chkper;
	var selCount=0;
	if (selects!=null)
	{
		if (selects.length!=null) //有两条以上的记录
		{	
			for (i=0;i<selects.length;i++)
			{
				if (selects[i].CompID==chkObj.CompID)
					selects[i].checked=ch;
			}
		}
	  	else
		{
			selects.checked=ch;
		}
	}
}

Ext.milan.pagejs.page_modulepermissions.chkAllClick = function(chkObj)
{
	var formEle =chkObj.form;
	var ch=false;
	var i=0;
	chkObj.checked=!chkObj.checked;
	if (chkObj.checked) 
	{
		chkObj.value="全不选";
		ch=true;
	}
	else
		chkObj.value="全选";
	
	var selects = formEle.CompChk;
	var selCount=0;
	if (selects!=null)
	{
		if (selects.length!=null) //有两条以上的记录
		{	
			for (i=0;i<selects.length;i++)
			{
				selects[i].checked=ch;
				Ext.milan.pagejs.page_modulepermissions.chkComp(selects[i]);
			}
		}
	  	else
		{
			selects.checked=ch;
			Ext.milan.pagejs.page_modulepermissions.chkComp(selects);
		}
	}
}

Ext.milan.pagejs.page_modulepermissions.showout = function(tableid,isshow)
{

	var tmpObj=$("table"+tableid);
	var imgObj=$("img"+tableid);
	
	if (tmpObj!=null)
	{
	
		if (isshow!=null) 
			if (isshow)
				tmpObj.style.display="none";
			else
				tmpObj.style.display="";
				
				
		if (tmpObj.style.display == "none")
		{
			imgObj.src=Milan.skinType+"images/minus.jpg";
			tmpObj.style.display="";
		}
		else
		{
			imgObj.src=Milan.skinType+"images/plus.jpg";
			tmpObj.style.display="none";
		}
	}
}

Ext.milan.pagejs.page_modulepermissions.expandall = function(btnobj)
{
	var formEle = btnobj.form;
	var complength=formEle.complength.value;
	var checked = false;
	if (btnobj.value=="全部展开"){
		btnobj.value = "全部收缩";
		checked =true;
	}else{
		btnobj.value="全部展开"
	}
	for (i=0;i<complength;i++)
		Ext.milan.pagejs.page_modulepermissions.showout(i,checked);
}

Ext.milan.pagejs.page_modulepermissions.showSetModulePermission = function(formId,psetIdName,plv)
{
	var formEle = $(formId);
	var curDate = new Date();
	formEle.psetIdName.value = psetIdName;
	var url = "auth/show.do?modIdName="+psetIdName;
	url=encodeURI(url); 
  	url=encodeURI(url);
	if (plv)
	{
		if(confirm("请注意:该权限需要[权限管理员]确认!"))//使用new Milan.widget.Dialog会使弹窗显示不良；
		{
			setModulePerWin = Milan.commonutils.createModelPop(
		    {
		        title: "权限设置-模块权限设置",
				height: "500px",
				width : "600px"
		    });
		    Milan.ajaxutility.updateContentUseAjax("post",url,setModulePerWin);	
		}
	}
	else
	{
		setModulePerWin = Milan.commonutils.createModelPop(
	    {
	        title: "权限设置-模块权限设置",
			height: "500px",
			width : "600px"
	    });
	    Milan.ajaxutility.updateContentUseAjax("post",url,setModulePerWin);	
	}
	
}

Ext.milan.pagejs.page_modulepermissions.hideWin=function(){
	if(setModulePerWin){
  	 	setModulePerWin.closeDialog();
   	}
}
